<?php


namespace app\api\library\index\getBanner;


use app\admin\model\MallBanner;
use app\api\model\MallUser;
use think\facade\Db;

class V
{
    public static function run($param)
    {
        $userId = $param[ 'userId' ];
        //查询有无openid
        $total    = MallBanner::where([['status', '=', 1], ['delete_time', '=', null]])->count();
        $banners  = MallBanner::where([['status', '=', 1], ['delete_time', '=', null]])->order(['sort' => 'desc', 'id' => 'desc'])->select();
        $banners  = $banners->toArray();
        $goodsIds = array_column($banners, 'link_goods_id');
        $goods    = Db::name('mall_goods')->where([['id', 'in', $goodsIds]])->select();
        $goods    = array_column($goods->toArray(), null, 'id');
        foreach ($banners as $key => $value) {
            $banners[ $key ][ 'is_novice' ] = $goods[ $value[ 'link_goods_id' ] ][ 'is_novices_exclusive' ] ?? 0;
        }
        $res = [
            'is_novice' => MallUser::where('id', $userId)->value('is_novice') ?? 0,
            'total'     => $total,
            'list'      => $banners,
        ];
        _outPut(200, $res);
    }
    
}